package own.stu.jobgib.playown.vediodown.common.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SimpleMediaItem {
    long id;
    String cover;
    String bvId;
    String title;
    long date;

    public String getCoverTitle() {
        return String.format(coverTitleFormat, id, title, getCoverSuffix());
    }

    public String getVedioTitle() {
        return String.format(vedioTitleFormat, id, title, getVedioSuffix());
    }

    private String getCoverSuffix() {
        int lastIndexOf = cover.lastIndexOf(".");
        if(lastIndexOf == -1){
            return "";
        }
        return cover.substring(lastIndexOf + 1);
    }

    private String getVedioSuffix() {
        // TODO
        return "mp4";
    }

    static String coverTitleFormat = "%d-%s.%s";
    static String vedioTitleFormat = "%d-%s.%s";

    public long getDate() {
        return date;
    }

    public void setDate(long date) {
        this.date = date;
    }

    public static void main(String[] args) {
        SimpleMediaItem item = new SimpleMediaItem();
        item.setBvId("BV1bo4y1Y7fw");
        item.setCover("http://i0.hdslb.com/bfs/archive/ddd7c0ef31d55305fd21959f6f6ae22279bd6bc4.jpg");
        item.setId(1L);
        item.setTitle("其实妈妈并不喜欢吃野菜 只是想多陪陪外婆而已");
        System.out.println(item.getCoverTitle());
    }
}